﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ExpertMIS.Service
{
    public partial class VerifyCode : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if ("1".Equals(Request["renew"]))
            {
                ExpertMIS.Codes.VerifyCode coder = new ExpertMIS.Codes.VerifyCode();

                int codeLen = 0;
                if (!int.TryParse(ExpertMIS.Codes.Utility.GetEnvironmentValue("verifycode.len"), out codeLen))
                {
                    codeLen = 4; // 默认值
                }

                coder.CodeSerial = "0,1,2,3,4,5,6,7,8,9";
                Session[Login.SESSION_KEY_VERIFYCODE] = coder.CreateVerifyCode(codeLen).ToLower();
            }

            ExpertMIS.Codes.VerifyCode verifyGenerator = new ExpertMIS.Codes.VerifyCode();
            int w = 0, h = 0;
            if (!int.TryParse(Request["w"], out w))
            {
                w = 70;
            }
            if (!int.TryParse(Request["h"], out h))
            {
                h = 20;
            }
            string code = Session[Login.SESSION_KEY_VERIFYCODE] as string;
            if (!string.IsNullOrEmpty(code))
            {
                verifyGenerator.FontSize = (int)w / code.Length;
                verifyGenerator.CreateImageOnPage(code, HttpContext.Current);
            }
        }
    }
}
